package org.zxl.springbootdemo.redis.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.zxl.springbootdemo.redis.dao.FriendMapper;
import org.zxl.springbootdemo.redis.entity.Friend;

/**
 * @author zhangxiaolong
 * @ClassName FriendService
 * @Description
 * @Date 2019/3/14 17:37
 * @Version 1.0
 **/
@Service
public class FriendService {
    @Autowired
    private FriendMapper friendMapper;

    @Cacheable(cacheNames = "friend", key = "#frId.toString()")
    public Friend findFriend2(Long frId){
        return friendMapper.findFriend(frId);
    }


    @Cacheable(cacheNames = "friend", key = "#frId.toString()")
    public Friend findFriend(Long frId){
        System.out.println("findFriend2 -------------");
        return new Friend();
    }

    @CacheEvict(cacheNames = "friend", key = "#frId.toString()")
    public void findFriend3(Long frId){
        System.out.println("findFriend3 -------------");
    }

    @CachePut(cacheNames = "friend", key = "#frId.toString()")
    public Friend findFriend4(Long frId){
        System.out.println("findFriend4 -------------");
        Friend friend = new Friend();
        friend.setFrId(4L);
        return friend;
    }

}
